/* $RCSFile: ShippingGtwBase.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/AddonNice.ECommerce.BankGateway/ShippingGtwBase.cs $
 * $log$
 * Revision 8 2010/08/09 10:07:05  christian.surieux
 *   Added Log comment to all cs files
 */

using System;
using System.Diagnostics;
using System.Configuration;
using System.Data;
using System.Collections;
using System.Collections.Specialized;

using AddonNice.ECommerce;

namespace AddonNice.ECommerce.Gateways.Shipping
{
	/// <summary>
	/// Summary description for ShippingGtwBase.
	/// </summary>
	public abstract class ShippingGtwBase : GtwBase
	{
        #region GtwBase overrides

        private Guid m_merchantID	=	Guid.Empty;
		/// <summary>
		/// Internal MerchantID generated in adn_EcommerceMerchants2
		/// </summary>
		public override Guid MerchantID
		{
			get 
			{
				return m_merchantID;
			}
			set 
			{
				m_merchantID = value;
			}
		}

		private NameValueCollection m_customSettings = new NameValueCollection();
		public override NameValueCollection CustomSettings
		{
			get {return m_customSettings;}
		}

        #endregion GtwBase overrides

		/// <summary>
		/// Warning each descendant must create its own unique ID
		/// </summary>
		public abstract	int ShippingsID
		{
			get;
		}
		
        public abstract bool IsElectronicDelivery
		{
			get;
		}
        
        public abstract bool IsShippingDelivery
		{
			get;
		}

        /// <summary>
		/// When true, the packing solver will be invoked to select a container and order items in it
        /// Else no packing is necessary
		/// </summary>
		public abstract	bool NeedPackaging
		{
			get;
		}

        private string _CartID	=	string.Empty;
		public string CartID
		{
			get
			{
				return _CartID;
			}
			set
			{
				if ( value != null )
					_CartID	=	value;
			}
		}

		private string _CountryID	=	string.Empty;
		public string CountryID
		{
			get
			{
				return _CountryID;
			}
			set
			{
				if ( value != null )
					_CountryID	=	value;
			}
		}

		private string _Currency	=	string.Empty;
		public string Currency
		{
			get
			{
				return _Currency;
			}
			set
			{
				if ( value != null )
					_Currency	=	value;
			}
		}

		public virtual ArrayList ProductList
		{
			get
			{
				return null;
			}
		}

		public virtual ArrayList PackingList
		{
			get
			{
				return null;
			}
		}

		public virtual decimal TotalShipping
		{
			get
			{
				return 0;
			}
		}
		
		public virtual void Init(string wCartID, string wCountryID,string wCurrency)
		{
			CartID				=	wCartID;
			CountryID			=	wCountryID;
			Currency			=	wCurrency;
		}
		/// <summary>
		/// Calculates the shipping cost of the cart.
		/// This will more likely change in future.
		/// </summary>
		public abstract decimal Calculate(string wCartID, string wCountryID,string wCurrency,decimal Total);

		public abstract bool ExistShipping(string wCartID, string wCountryID,string wCurrency);

        /// <summary>
		/// PostprocessCheck verifies that cost makes sense.
		/// Can be overridden in derived class for add more checks.
		/// It is recommended calling 
		/// return base.PostprocessCheck(inputMoney)
		/// in all derived classes. 
		/// </summary>
		protected virtual decimal PostprocessCheck(decimal inputMoney)
		{
			if( inputMoney < 0m )
				throw new Exception("[E]ShippingGtwBase PostProcessCheck negative amout.");
			return inputMoney;
		}
		
		decimal m_maxValue = 999999m;
		/// <summary>
		/// Total shipping will not be more than specified value.
		/// 0 means no limit.
		/// </summary>
		public decimal MaxValue
		{
			get
			{
				return m_maxValue;
			}
			set
			{
				if (value < MinValue)
					throw new ArgumentException("[E]ShippingGtwBase MaxValue must be greater than MinValue");
				m_maxValue = value;
			}
		}

		decimal m_minValue = 0;
		/// <summary>
		/// Total shipping will not be less than specified value. 
		/// </summary>
		public decimal MinValue
		{
			get
			{
				return m_minValue;
			}
			set
			{
				if (value > MaxValue)
					throw new ArgumentException("[E]ShippingGtwBase MinValue must be lower than MaxValue");
				m_minValue = value;
			}
		}
	}
}